﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CustomizedCommandXMLChecker.CUICustomizedCommandXMLCheckerForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Olp;
using Tecnomatix.Engineering.Olp.CustomizedTemplate;
using Tecnomatix.Engineering.Olp.RoboticPathTemplate;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CustomizedCommandXMLChecker;

public class CUICustomizedCommandXMLCheckerForm : TxForm
{
  private IContainer components;
  private Button CheckButton;
  private Button CloseButton;
  private Label label1;
  private TxRichTextBox richTextBox1;
  private Button help_button;
  private Button EncryptBtn;
  private OpenFileDialog openFileDialog1;
  private Button ReprotBtn;

  internal TxRobot Robot { get; set; }

  public CUICustomizedCommandXMLCheckerForm(TxRobot robot)
  {
    this.Robot = robot;
    this.InitializeComponent();
    ((Control) this).Text = $"{((Control) this).Text} [{this.Robot.Controller.Name}]";
    TxOLPUtilities txOlpUtilities = new TxOLPUtilities();
    if (!new FileInfo(TxApplication.InstallationDirectory + "\\Help\\Additional Reference Material\\RoboticsCustomizedUIManual.pdf").Exists)
      this.help_button.Enabled = false;
    ((Control) this.richTextBox1).BackColor = Color.White;
  }

  private void CloseButton_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void ShowError(object excep)
  {
    switch (excep)
    {
      case TxOlpXMLException _:
        TxOlpXMLException txOlpXmlException = excep as TxOlpXMLException;
        if (!txOlpXmlException.XMLSource.Equals(""))
        {
          string str = txOlpXmlException.XMLSource;
          if (str.Contains("file:///"))
            str = str.Remove(0, 8);
          ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
          ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.File + "\n");
          ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
          ((TextBoxBase) this.richTextBox1).AppendText(str + "\n\n");
        }
        if (!txOlpXmlException.PathInfo.Equals(""))
        {
          ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
          ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Path + "\n");
          ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
          ((TextBoxBase) this.richTextBox1).AppendText(txOlpXmlException.PathInfo + "\n\n");
        }
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
        if (excep is TxOlpXMLMissingOlpConfigurationFileException)
        {
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Warning");
          ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Warning);
          ((TextBoxBase) this.richTextBox1).AppendText("\n");
          ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Warning");
        }
        else
        {
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Error");
          ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Error);
          ((TextBoxBase) this.richTextBox1).AppendText("\n");
          ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Error");
        }
        ((TextBoxBase) this.richTextBox1).AppendText(((Exception) txOlpXmlException).Message);
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
        if (!(excep is TxOlpXMLMissingOlpConfigurationFileException))
        {
          ((TextBoxBase) this.richTextBox1).AppendText("\n\n" + CapCustomizedCommandXMLCheckerStringTable.Fix);
          break;
        }
        break;
      case NullReferenceException _:
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Error");
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Error + "\n");
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Error");
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.UnKnownError);
        break;
      case Exception _:
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
        ((TextBoxBase) this.richTextBox1).AppendText((excep as Exception).Message + "\n\n");
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Fix);
        break;
    }
    ((TextBoxBase) this.richTextBox1).AppendText("\n\n");
  }

  public void Check()
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    bool flag1 = true;
    TxOLPUtilities txOlpUtilities = new TxOLPUtilities();
    ((TextBoxBase) this.richTextBox1).Clear();
    try
    {
      ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
      ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
      ((TextBoxBase) this.richTextBox1).AppendText("DataConfiguration");
      ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
      ((TextBoxBase) this.richTextBox1).AppendText(": ");
      new TxOlpDataServices(this.Robot).Refresh();
      ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Valid + "\n\n");
    }
    catch (Exception ex)
    {
      ((TextBoxBase) this.richTextBox1).AppendText("\n");
      flag1 = false;
      this.ShowError((object) ex);
      if (ex is TxOlpXMLMissingOlpConfigurationFileException)
        flag1 = true;
    }
    try
    {
      if (flag1)
      {
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
        ((TextBoxBase) this.richTextBox1).AppendText("OlpConfiguration");
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
        ((TextBoxBase) this.richTextBox1).AppendText(": ");
        new TxOlpCommandServices(this.Robot).Refresh();
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Valid + "\n\n");
      }
    }
    catch (Exception ex)
    {
      ((TextBoxBase) this.richTextBox1).AppendText("\n");
      flag1 = false;
      this.ShowError((object) ex);
      if (ex is TxOlpXMLMissingOlpConfigurationFileException)
        flag1 = true;
    }
    try
    {
      if (flag1)
      {
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
        ((TextBoxBase) this.richTextBox1).AppendText("MotionConfiguration");
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
        ((TextBoxBase) this.richTextBox1).AppendText(": ");
        new TxOlpMotionCommandServices(this.Robot).Refresh();
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Valid + "\n\n");
      }
    }
    catch (Exception ex)
    {
      ((TextBoxBase) this.richTextBox1).AppendText("\n");
      flag1 = false;
      this.ShowError((object) ex);
      if (ex is TxOlpXMLMissingOlpConfigurationFileException)
        flag1 = true;
    }
    try
    {
      if (flag1)
      {
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
        ((TextBoxBase) this.richTextBox1).AppendText("PathTemplateConfiguration");
        ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
        ((TextBoxBase) this.richTextBox1).AppendText(": ");
        new TxOlpPathTemplateServices().LoadControllerXMLInfo((ITxRobotController) this.Robot.Controller);
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Valid + "\n\n");
      }
    }
    catch (Exception ex)
    {
      ((TextBoxBase) this.richTextBox1).AppendText("\n");
      flag1 = false;
      this.ShowError((object) ex);
      if (ex is TxOlpXMLMissingOlpConfigurationFileException)
        flag1 = true;
    }
    try
    {
      if (!flag1)
        return;
      ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Bold | FontStyle.Underline);
      ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
      ((TextBoxBase) this.richTextBox1).AppendText("DownloadTemplatesConfiguration");
      ((RichTextBox) this.richTextBox1).SelectionFont = new Font(((Control) this).Font, FontStyle.Regular);
      ((TextBoxBase) this.richTextBox1).AppendText(": ");
      new TxOlpDownloadTemplateServices((ITxRobotController) this.Robot.Controller).Refresh();
      ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.Valid + "\n\n");
    }
    catch (Exception ex)
    {
      ((TextBoxBase) this.richTextBox1).AppendText("\n");
      bool flag2 = false;
      this.ShowError((object) ex);
      if (!(ex is TxOlpXMLMissingOlpConfigurationFileException))
        return;
      flag2 = true;
    }
    finally
    {
      Cursor.Current = current;
    }
  }

  private void CheckButton_Click(object sender, EventArgs e) => this.Check();

  private void help_button_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    Process.Start(TxApplication.InstallationDirectory + "\\Help\\Additional Reference Material\\RoboticsCustomizedUIManual.pdf");
    Cursor.Current = current;
  }

  private void EncryptBtn_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.openFileDialog1.Multiselect = true;
    this.openFileDialog1.Filter = "XML files |*.xml";
    this.openFileDialog1.Title = CapCustomizedCommandXMLCheckerStringTable.EncryptionTitle;
    this.openFileDialog1.FileName = "";
    this.openFileDialog1.InitialDirectory = new TxOLPUtilities().GetOLPInstallationDirectory();
    if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
    {
      ((TextBoxBase) this.richTextBox1).Clear();
      bool flag;
      string text = new TxOlpXMLSecurity().EncryptFiles(this.openFileDialog1.FileNames, ref flag);
      if (flag)
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
      else
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Error");
      ((TextBoxBase) this.richTextBox1).AppendText(text);
    }
    Cursor.Current = current;
  }

  private void Report_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.openFileDialog1.Multiselect = true;
    this.openFileDialog1.Filter = "XML files |*.xml*";
    this.openFileDialog1.Title = CapCustomizedCommandXMLCheckerStringTable.ReportTitle;
    this.openFileDialog1.FileName = "";
    this.openFileDialog1.InitialDirectory = new TxOLPUtilities().GetOLPInstallationDirectory();
    if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
    {
      List<string> stringList = new TxOlpReport().Report(this.openFileDialog1.FileNames);
      ((TextBoxBase) this.richTextBox1).Clear();
      if (stringList.Count == 0)
      {
        ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Error");
        ((TextBoxBase) this.richTextBox1).AppendText(CapCustomizedCommandXMLCheckerStringTable.InValid);
      }
      else
      {
        for (int index = 0; index + 1 < stringList.Count; index += 2)
        {
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Info");
          ((TextBoxBase) this.richTextBox1).AppendText(stringList[index]);
          ((TextBoxBase) this.richTextBox1).AppendText("\n");
          ((RichTextBox) this.richTextBox1).SelectionColor = TxStatusColor.TextWithoutBackground("Emphasize7");
          ((TextBoxBase) this.richTextBox1).AppendText(stringList[index + 1]);
          ((TextBoxBase) this.richTextBox1).AppendText("\n");
        }
      }
    }
    Cursor.Current = current;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUICustomizedCommandXMLCheckerForm));
    this.CheckButton = new Button();
    this.CloseButton = new Button();
    this.label1 = new Label();
    this.richTextBox1 = new TxRichTextBox();
    this.help_button = new Button();
    this.EncryptBtn = new Button();
    this.openFileDialog1 = new OpenFileDialog();
    this.ReprotBtn = new Button();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.CheckButton, "CheckButton");
    this.CheckButton.Name = "CheckButton";
    this.CheckButton.UseVisualStyleBackColor = true;
    this.CheckButton.Click += new EventHandler(this.CheckButton_Click);
    componentResourceManager.ApplyResources((object) this.CloseButton, "CloseButton");
    this.CloseButton.Name = "CloseButton";
    this.CloseButton.UseVisualStyleBackColor = true;
    this.CloseButton.Click += new EventHandler(this.CloseButton_Click);
    componentResourceManager.ApplyResources((object) this.label1, "label1");
    this.label1.Name = "label1";
    componentResourceManager.ApplyResources((object) this.richTextBox1, "richTextBox1");
    ((Control) this.richTextBox1).Name = "richTextBox1";
    ((TextBoxBase) this.richTextBox1).ReadOnly = true;
    componentResourceManager.ApplyResources((object) this.help_button, "help_button");
    this.help_button.Name = "help_button";
    this.help_button.UseVisualStyleBackColor = true;
    this.help_button.Click += new EventHandler(this.help_button_Click);
    componentResourceManager.ApplyResources((object) this.EncryptBtn, "EncryptBtn");
    this.EncryptBtn.Name = "EncryptBtn";
    this.EncryptBtn.UseVisualStyleBackColor = true;
    this.EncryptBtn.Click += new EventHandler(this.EncryptBtn_Click);
    componentResourceManager.ApplyResources((object) this.ReprotBtn, "ReprotBtn");
    this.ReprotBtn.Name = "ReprotBtn";
    this.ReprotBtn.UseVisualStyleBackColor = true;
    this.ReprotBtn.Click += new EventHandler(this.Report_Click);
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).Controls.Add((Control) this.ReprotBtn);
    ((Control) this).Controls.Add((Control) this.EncryptBtn);
    ((Control) this).Controls.Add((Control) this.help_button);
    ((Control) this).Controls.Add((Control) this.richTextBox1);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Control) this).Controls.Add((Control) this.CloseButton);
    ((Control) this).Controls.Add((Control) this.CheckButton);
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUICustomizedCommandXMLCheckerForm);
    this.SemiModal = false;
    this.ShouldCloseOnDocumentUnloading = true;
    ((Form) this).SizeGripStyle = SizeGripStyle.Hide;
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
